package com.blueocean.care.management.Controller;

import com.blueocean.care.management.domain.SysResult;
import com.netflix.zuul.context.RequestContext;
import org.springframework.boot.autoconfigure.web.ErrorController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @version 1.0
 * @author: zwg.BlueOcean
 * @date 2018/7/31 14:00
 * @description
 */
@RestController
public class CustomErrorController implements ErrorController{
    @Override
    public String getErrorPath() {
        return "/error";
    }
    @RequestMapping("/error")
    public SysResult doHandleError(){
        RequestContext ctx = RequestContext.getCurrentContext();
        Throwable throwable=ctx.getThrowable();
        /**
         * 循环获取，拿到最底层的异常原因
         */
        while (throwable.getCause()!=null){
            throwable=throwable.getCause();
        }
        return SysResult.ERROR(10000,throwable.getMessage());
    }
}
